<?php
namespace application\index\controller;
use application\index\model\ArticleFront;
class Ar extends CController
{
	/**
	 * 首页
	 */
    public function index()
    {
    	//最新发布
    	$articleFront = new ArticleFront();
    	$this->_G = array_merge($this->_G, $articleFront->indexData());

    	$this->assign('_G', $this->_G);
    	return $this->fetch();
    }
    /**
     * 详情页
     * @return mixed  
     */
    public function detail()
    {
    	$aid = input('aid', '');
        if(!$aid) {
            $this->redirect('ar/index');
            die();
        }
        $articleFront = new ArticleFront();
        $res = $articleFront->detail($aid);
        if(!$res) {
            $this->redirect('ar/index');
            die();
        }
        $this->_G = array_merge($this->_G, $res);
        $this->_G['title'] = $this->_G['article']['title'];
        $this->_G['description'] = $this->_G['article']['summary'];
    	$this->assign('_G', $this->_G);
    	return $this->fetch();
    }    
    /**
     * 列表页面
     * @return mixed  
     */
    public function cat()
    {
    	$id = input('id', '');
        $page = intval(input('page', 1));
        $psize= intval(input('psize', 10));
    	if(!$id) {
    		$this->redirect('ar/index');
    		die();
    	}
        $articleFront = new ArticleFront();
        $this->_G = array_merge($this->_G, $articleFront->catData($id, $page, $psize));
    	$this->_G['title'] = $this->_G['site']['name'] . '-' . $this->_G['catinfo']['cat_name'] ;
    	$this->assign('_G', $this->_G);
    	return $this->fetch();
    }
    /**
     * 查看评论
     */
    public function comment()
    {
        $aid   = input('aid', '');
        $page  = intval(input('page', 1));
        $psize = intval(input('psize', 25));
        if(!$aid) {
            $this->redirect('ar/index');
            die();
        }
        $articleFront = new ArticleFront();
        $this->_G = array_merge($this->_G, $articleFront->commentData($aid, $page, $psize));
        $this->_G['title'] = $this->_G['site']['name'] . '-' . $this->_G['article']['title'];
        $this->assign('_G', $this->_G);
        return $this->fetch();
    }
    /**
     * 评论回复
     */
    public function reply()
    {
        $articleFront = new ArticleFront();
        if($articleFront->reply()) {
            ajaxResponse('200', 'success');
        } else {
            ajaxResponse($articleFront->code, $articleFront->message);
        }
    }
}
